# 创建进程
import os
from multiprocessing import Process
from time import sleep

m = 1  # 不可变类型
list1 = []  # 可变类型


def task1(s, name):
    global m
    while True:
        sleep(s)
        m += 1
        list1.append(str(m) + 'task1')
        print('这是任务1: ', m, list1)


# os.getpid()获取进程号, os.getppid()获取父进程号

def task2(s, name):
    global m
    while True:
        sleep(s)
        m += 1
        list1.append(str(m) + 'task2')
        print('这是任务2: ', m, list1)


number = 1
if __name__ == '__main__':
    print(os.getpid())
    # p1和p2是主进程创建的两个子进程
    p1 = Process(target=task1, name='任务1', kwargs={'s': 1, 'name': 'aa'})
    p1.start()
    p2 = Process(target=task2, name='任务2', args=(2, 'bb'))
    p2.start()
    while True:
        sleep(1)
        m += 1
        list1.append(str(m) + 'main')
        print('main: ', m, list1)
